﻿Imports WindowsApplication1.com.roche.intranet.jira
Imports Microsoft.SharePoint.Client

Public Class Form1

    Dim client As New com.roche.intranet.jira.JiraSoapServiceService
    Dim token As String = client.login("login", "password")


    Private Sub Button1Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

        Me.Cursor = Cursors.WaitCursor
        Dim listRv(0) As com.roche.intranet.jira.RemoteVersion
        Dim listRc(0) As com.roche.intranet.jira.RemoteComponent

        Dim newIssue As New com.roche.intranet.jira.RemoteIssue
        newIssue.assignee = ComboBoxUserName.Text
        newIssue.summary = TxtPrefix.Text + " " + txtSummary.Text
        newIssue.description = TxtDescription.Text


        Dim rv As com.roche.intranet.jira.RemoteVersion = New com.roche.intranet.jira.RemoteVersion()
        rv.id = "15301"
        Dim rc As New com.roche.intranet.jira.RemoteComponent
        rc.id = "12910"
        listRv.SetValue(rv, 0)
        listRc.SetValue(rc, 0)
        newIssue.fixVersions = listRv
        newIssue.components = listRc


        newIssue.project = "OTRCEMAI"
        newIssue.type = 40
        newIssue.priority = 3
        Dim createdIssue As com.roche.intranet.jira.RemoteIssue = client.createIssue(token, newIssue)

        MessageBox.Show("created ticket no:" + createdIssue.key)
        Me.Cursor = Cursors.Arrow

    End Sub


    Public Sub New()

        ' This call is required by the designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        'loadVersions()
        'loadComponents()
        'loadTypes()
    End Sub

 

    Private Sub Button2Click1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim ticketNo As String = CreateIssue(ComboBoxUserName.Text, TxtPrefix.Text + " " + txtSummary.Text, TxtDescription.Text, ComboBoxProj.Text, ComboType.Text, ComboBoxFix.SelectedValue, ComboBoxAffected.Text, ComboComponent.SelectedValue)
        MessageBox.Show("created ticket no:" + ticketNo)
    End Sub


    Public Function CreateIssue(ByVal assignee As String, ByVal summary As String, ByVal description As String, ByVal project As String, ByVal IssueType As String, ByVal fixVersion As String, ByVal affVersion As String, ByVal component As String) As String
        Me.Cursor = Cursors.WaitCursor

        Dim oldIssues As com.roche.intranet.jira.RemoteIssue = client.getIssue(token, "ESD-285")

        Dim listRv(0) As com.roche.intranet.jira.RemoteVersion
        Dim listRaff(0) As com.roche.intranet.jira.RemoteVersion
        Dim listRc(0) As com.roche.intranet.jira.RemoteComponent

        Dim newIssue As New com.roche.intranet.jira.RemoteIssue
        newIssue.assignee = assignee
        newIssue.summary = summary
        newIssue.description = description


        Dim rv As com.roche.intranet.jira.RemoteVersion = New com.roche.intranet.jira.RemoteVersion()
        rv.id = fixVersion

        Dim raff As com.roche.intranet.jira.RemoteVersion = New com.roche.intranet.jira.RemoteVersion()
        Dim verlist() As com.roche.intranet.jira.RemoteVersion = client.getVersions(token, ComboBoxProj.Text)
        For Each RemoteVersion In verlist
            If RemoteVersion.name = affVersion Then
                raff = RemoteVersion
            End If
        Next


        Dim rc As New com.roche.intranet.jira.RemoteComponent
        rc.id = component
        listRv.SetValue(rv, 0)
        listRaff.SetValue(raff, 0)
        listRc.SetValue(rc, 0)

        newIssue.fixVersions = listRv
        newIssue.affectsVersions = listRaff
        newIssue.components = listRc


        newIssue.project = project
        newIssue.type = IssueType
        newIssue.priority = 3
        Dim createdIssue As com.roche.intranet.jira.RemoteIssue = client.createIssue(token, newIssue)

        Me.Cursor = Cursors.Arrow
        Return createdIssue.key
    End Function



    Private Sub Change(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBoxProj.SelectedIndexChanged
        Try
            loadVersions()
            loadComponents()
            LoadVersionsAffected()
            'LoadTypes()
            LoadRequestTypes()
        Catch ex As Exception
        End Try
    End Sub


    Public Sub LoadVersions()
        Dim verlist() As com.roche.intranet.jira.RemoteVersion = client.getVersions(token, ComboBoxProj.Text)
        ComboBoxFix.DataSource = verlist
        ComboBoxFix.DisplayMember = "name"
        ComboBoxFix.ValueMember = "id"
        'ComboBoxFix.Sorted = True
        ComboBoxFix.Refresh()

    End Sub

    Public Sub LoadVersionsAffected()
        Dim verlist() As com.roche.intranet.jira.RemoteVersion = client.getVersions(token, ComboBoxProj.Text)

        Dim kolekcja As New ArrayList


        For Each remoteversion In verlist
            If remoteversion.released = True Then
                kolekcja.Add(remoteversion)
            End If
        Next


        ComboBoxAffected.DataSource = kolekcja
        ComboBoxAffected.DisplayMember = "name"
        ComboBoxAffected.ValueMember = "id"

        'ComboBoxAffected.Sorted = True
        ComboBoxAffected.Refresh()
    End Sub

    Public Sub LoadComponents()
        Dim comlist() As com.roche.intranet.jira.RemoteComponent = client.getComponents(token, ComboBoxProj.Text)
        ComboComponent.DataSource = comlist
        ComboComponent.DisplayMember = "name"
        ComboComponent.ValueMember = "id"
        'ComboComponent.Sorted = True
        ComboComponent.Refresh()
    End Sub

    Public Sub LoadTypes()
        Dim typlist() As com.roche.intranet.jira.RemoteIssueType = client.getIssueTypes(token)
        ComboType.DataSource = typlist
        ComboType.DisplayMember = "name"
        ComboType.ValueMember = "id"
        ComboType.Refresh()
    End Sub

    Public Sub LoadRequestTypes()
        'Dim typlist As New ArrayList
        'typlist.Add("1")
        'typlist.Add("40")
        'typlist.Add("40")

        'ComboType.DataSource = typlist
        'ComboType.Refresh()

        ' ComboType.Items.Add(""
    End Sub


End Class
